import numpy as np
import os
os.chdir(os.path.dirname(__file__)) 

def save_image_to_file(image, filename):
    with open(filename, 'wb') as file:
        # 将整个图像数组以二进制形式写入文件
        file.write(image.tobytes())


def gen_0a20_image(width,height):
    base_image = np.zeros((height,width),dtype='uint16')
    for row in range(height):
        for col in range(width):
            # 计算当前组内的偏移量
            offset = 256-(col % 256)-1
            # 每组从255递减到0
            base_image[row, col] = (row*256)%65536+offset
    return base_image

def gen_0a60_image(width,height):
    base_image = np.zeros((height,width),dtype='uint16')
    for row in range(height):
        for col in range(width):
            i=col % 256
            offset = (255 - (i // 64)) - 4 * (i % 64)
            base_image[row, col] = (row*256)%65536+offset
    return base_image

# 参数化长宽
width = 2560  # 图像宽度，必须是256的倍数
height = 2048    # 图像高度

# 生成图像
image_0a20 = gen_0a20_image(width, height)

# 打印生成的图像（部分）
print(image_0a20[:1, :])

# 保存图像到文件
save_image_to_file(image_0a20, "image_0a20.raw")

# 生成图像
image_0a60 = gen_0a60_image(width, height)

# 打印生成的图像（部分）
print(image_0a60[:1, :])

# 保存图像到文件
save_image_to_file(image_0a60, "image_0a60.raw")